package IBBB.network.sendmessage;


import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class send_string_obj<T> implements  Runnable {
    String serverIP;
    final int PORT_NUMBER=8088;
    Socket message_socket;
    ObjectOutputStream send_message;
    String target_message;
    T data_message;
    //String local_ip=new LocalIP().get_local_ip();//测试用local_ip，预留接口
    send_string_obj(String server) {
        serverIP = server;
        try {
            message_socket = new Socket(serverIP, PORT_NUMBER);
            send_message = new ObjectOutputStream(message_socket.getOutputStream());
        } catch (UnknownHostException e) {
            e.printStackTrace();
            System.out.println("The wrong server IP Exception");
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("Trouble in initializing the send_message_socket");
        }
    }
    @Override
    public void run() {
        try {
            send_message.writeObject(target_message);
            send_message.writeObject(data_message);
        }catch(IOException e){
            e.printStackTrace();
            System.out.println("IO problem in send_String");
        }
    }
}
